﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.IBLL;
using KPIS.GERP.GIMS.IDAL;
using KPIS.GERP.GIMS.DALFactory;

namespace KPIS.GERP.GIMS.BLL
{
    public class MasterCommitteeMappingBLL : IBLLMasterCommitteeMapping
    {
        private static readonly IDALMasterCommitteeMapping dal = DataAccess.CreateMasterCommitteeMapping();

        public MasterCommitteeMappingBLL()
        {

        }

        public IList<MasterCommitteeMappingInfo> GetMasterCommitteeMapping()
        {
            return dal.GetMasterCommitteeMapping();
        }

        public IList<MasterCommitteeMappingInfo> GetMasterCommitteeMapping(string record_status)
        {
            return dal.GetMasterCommitteeMapping(record_status);
        }

        public MasterCommitteeMappingInfo GetMasterCommitteeMapping(int seq)
        {
            return dal.GetMasterCommitteeMapping(seq);
        }

        public IList<MasterCommitteeMappingInfo> GetMasterCommitteeMappingWithMethod(int map_seq)
        {
            return dal.GetMasterCommitteeMappingWithMethod(map_seq);
        }

        public IList<MasterCommitteeMappingInfo> GetMasterCommitteeMappingWithFunction(int map_seq, int func_seq)
        {
            return dal.GetMasterCommitteeMappingWithFunction(map_seq, func_seq);
        }
        public int GetMaxNumberComFunction(int map_seq)
        {
            return dal.GetMaxNumberComFunction(map_seq);
        }

        public void Insert(IList<MasterCommitteeMappingInfo> infoList)
        {
            try
            {
                dal.Insert(infoList);
            }
            catch
            {
                throw;
            }
        }

        public void Update(MasterCommitteeMappingInfo info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(MasterCommitteeMappingInfo info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }

        public void DeleteAll(IList<MasterCommitteeMappingInfo> infoList)
        {
            try
            {
                dal.DeleteAll(infoList);
            }
            catch
            {
                throw;
            }
        }

        public void DeleteFromDB(IList<MasterCommitteeMappingInfo> infoList)
        {
            try
            {
                dal.DeleteFromDB(infoList);
            }
            catch
            {
                throw;
            }
        }

        public void Restore(IList<MasterCommitteeMappingInfo> infoList)
        {
            try
            {
                dal.Restore(infoList);
            }
            catch
            {
                throw;
            }
        }

        public void CheckData(MasterCommitteeMappingInfo info)
        {
            try
            {
                if (info.Amount_type == "<")
                {
                    if (info.Min_amount == null)
                    {
                        throw new Exception("กรุณาระบุวงเงินให้ครบถ้วน");
                    }
                }
                else if (info.Amount_type == "-")
                {
                    if (info.Min_amount > info.Max_amount)
                    {
                        throw new Exception("วงเงินเริ่มต้นต้องน้อยกว่าวงเงินสูงสุด");
                    }
                    if (info.Min_amount == null || info.Max_amount == null)
                    {
                        throw new Exception("กรุณาระบุวงเงินให้ครบถ้วน");
                    }
                }
                else if (info.Amount_type == ">")
                {
                    if (info.Max_amount == null)
                    {
                        throw new Exception("กรุณาระบุวงเงินให้ครบถ้วน");
                    }
                }
            }
            catch
            {
                throw;
            }
        }
    }
}
